package com.zzw.design.observer;

import java.util.Observable;

public class Writer extends Observable{

	private String name;
	
	private String lastNovel;
	
	public Writer(String name){
		super();
		this.name = name;
		WriterManger.getInstance().add(this);
	}
	
	public void addNovel(String novel){
		System.out.println(name + "���������顶" + novel + "����");
		lastNovel = novel;
		setChanged();
		notifyObservers();
	}
	
	public String getLastNovel() {
		return lastNovel;
	}
	
	public String getName() {
		return name;
	}
	
	public static void main(String[] args) {
		//�����ĸ����ߣ���������
        Reader r1 = new Reader("л����");
        Reader r2 = new Reader("����");
        Reader r3 = new Reader("�߸�");
        Reader r4 = new Reader("����");
        Writer w1 = new Writer("л���");
        Writer w2 = new Writer("��С��");
        //���˹�ע��л���
        r1.subscribe("л���");
        r2.subscribe("л���");
        r3.subscribe("л���");
        r4.subscribe("л���");
        //�߸�����ܻ���ע����С��
        r3.subscribe("��С��");
        r4.subscribe("��С��");
        
        //���߷�������ͻ�֪ͨ��ע�Ķ���
        //л���д�����ģʽ
        w1.addNovel("���ģʽ");
        //��С��д��JAVA���˼��
        w2.addNovel("JAVA���˼��");
        //л����ȡ����עл���
        r1.unsubscribe("л���");
        //л�����д�齫����֪ͨл����
        w1.addNovel("�۲���ģʽ");
	}
   
}
